package com.atmk.atmk.designMode.创建型.单例模式.懒汉式;

import java.util.stream.IntStream;

/*
* 线程不安全（不要使用）
* */
public class Singleton3 {
    private static Singleton3 singleton3;

    private Singleton3() {
    }

    public static Singleton3 getSingleton3() {
        if (singleton3 == null) {
            try {
                Thread.sleep(100); // 假设实例化需要一定时间
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            singleton3 = new Singleton3();
        }
        return singleton3;
    }


    public static void main(String[] args) {
        IntStream.range(1,10000)
                .forEach(i->{
                    new Thread(()->{
                            System.out.println("第"+i+"个："+ Singleton3.getSingleton3().hashCode());;
                    }).start();
                });
    }


}
